import { defineStore } from "pinia";
import { ref } from "vue";
import { store } from "./index";
import { self } from "@/api/auth";

const KEY = "user";

/**
 * 用户信息
 */
export const useUserStore = defineStore(KEY, () => {
  const userInfo = ref({} as any);

  async function load() {
    try {
      const { loadingStore } = store();
      loadingStore.loading("加载国际化配置...");
      const { data } = await self();
      userInfo.value = data;
    } catch (ex) {
      console.log("加载用户信息失败");
    }
  }

  function get() {
    return userInfo.value;
  }

  return {
    load,
    get,
  };
});
